import { citys } from "@/assets/data/citys";

const userAddOption: object = {
  size: "large",
  labelWidth: 150,
  submitBtn: true,
  emptyBtn: true,
  column: [
    {
      label: "手机号",
      span: 24,
      prop: "mobile",
      rules: [
        { required: true, message: "请输入联系电话", validator: validPhone, trigger: "blur" },
      ],
    },
    {
      label: "姓名",
      span: 8,
      prop: "name",
      rules: [{ required: true, message: "请输入姓名", trigger: "blur" }],
    },
    {
      label: "性别",
      span: 8,
      prop: "sex",
      type: "select",
      dicData: [
        { label: "男", value: "男" },
        { label: "女", value: "女" },
      ],
      rules: [{ required: true, message: "请选择性别", trigger: "blur" }],
    },
    {
      label: "户籍所在地",
      span: 8,
      prop: "domiciles",
      type: "cascader",
      dicData: citys,
      filterable: true,
      rules: [{ required: true, message: "请选择户籍所在地", trigger: "blur" }],
      props: {
        label: "label",
        value: "label",
        children: "children",
      },
    },
    {
      label: "身份证号码",
      span: 16,
      prop: "id_card",
      rules: [
        { required: true, message: "请输入身份证号码", trigger: "blur" },
        {
          validator: validIdCard,
          trigger: "blur",
        },
      ],
    },
    {
      label: "出生日期",
      span: 8,
      prop: "birthday",
      type: "date",
      valueFormat: "YYYY-MM-DD",
      rules: [{ required: true, message: "请选择出生日期", trigger: "blur" }],
    },
    {
      label: "申请改造家庭住址",
      span: 8,
      prop: "address_citys",
      type: "cascader",
      dicData: citys,
      filterable: true,
      props: {
        label: "label",
        value: "label",
        children: "children",
      },
      rules: [{ required: true, message: "请选择所在地", trigger: "blur" }],
    },

    {
      label: "住址详情",
      span: 16,
      prop: "address_detail",
      type: "map",
      rules: [{ required: true, message: "请输入详细地址", trigger: "blur" }],
    },

    {
      label: "家庭基本情况",
      span: 24,
      type: "textarea",
      prop: "family_situation",
      rules: [{ required: true, message: "请输入家庭基本情况", trigger: "blur" }],
    },

    {
      label: "住宅情况",
      span: 6,
      type: "radio",
      prop: "house_situation",
      dicData: [
        { label: "自有", value: "自有" },
        { label: "租赁", value: "租赁" },
        { label: "其他", value: "其他" },
      ],
      rules: [{ required: true, message: "请选择", trigger: "blur" }],
    },

    {
      label: "房产证号",
      span: 6,
      prop: "house_number",
    },

    {
      label: "家庭人数",
      span: 5,
      prop: "family_number",
      type: "number",
      value: 1,
      rules: [{ required: true, message: "请输入家庭人数", trigger: "blur" }],
    },
    {
      label: "老年人数",
      span: 5,
      prop: "elderly_number",
      type: "number",
      value: 1,
      rules: [{ required: true, message: "请输入老年人数", trigger: "blur" }],
    },
    {
      label: "家庭联系人",
      span: 12,
      prop: "family_contact",
      rules: [{ required: true, message: "请输入家庭联系人", trigger: "blur" }],
    },
    {
      label: "联系电话",
      span: 12,
      prop: "family_contact_phone",
      rules: [
        { required: true, message: "请输入联系电话", trigger: "blur" },
        { validator: validPhone, trigger: "blur" },
      ],
    },
    {
      label: "身份特征",
      span: 24,
      type: "radio",
      prop: "identity_characteristics",
      dicData: [
        { label: "分散供养特困老年人家庭", value: "分散供养特困老年人家庭" },
        { label: "城乡低保老年人家庭", value: "城乡低保老年人家庭" },
        { label: "低保边缘、低收入人口老年人家庭", value: "低保边缘、低收入人口老年人家庭" },
        { label: "计划生育特殊老年人家庭", value: "计划生育特殊老年人家庭" },
        { label: "其他:60周岁以上老年人家庭", value: "60周岁以上老年人家庭" },
      ],
      rules: [{ required: true, message: "请选择身份特征", trigger: "blur" }],
    },
    {
      label: "拟申请改造项目",
      span: 24,
      type: "checkbox",
      prop: "project_items",
      dicData: [
        { label: "防滑处理", value: "防滑处理" },
        { label: "高差处理", value: "高差处理" },
        { label: "安装床边护栏(抓杆)", value: "安装床边护栏(抓杆)" },
        { label: "安装扶手", value: "安装扶手" },
        { label: "手杖", value: "手杖" },
        { label: "防走失装置", value: "防走失装置" },
      ],
      rules: [{ required: true, message: "请选择拟申请改造项目", trigger: "blur" }],
    },

    {
      labelWidth: 200,
      label: "拟申请改造项目(其他项目)",
      span: 24,
      prop: "project_other",
    },

    {
      label: "街道(乡镇)意见",
      span: 24,
      labelWidth: 200,
      prop: "street_result",
      type: "radio",
      dicData: [
        { label: "同意", value: 1 },
        { label: "拒绝", value: 0 },
      ],
    },

    {
      label: "县(市、区)级民政部门意见",
      span: 24,
      prop: "civil_result",
      labelWidth: 200,
      type: "radio",
      dicData: [
        { label: "同意", value: 1 },
        { label: "拒绝", value: 0 },
      ],
    },
  ],
};

export default userAddOption;

/**
 * 验证身份证号码的合法性
 *
 * @param rule 验证规则对象，用于定义验证的规则和条件
 * @param value 待验证的身份证号码字符串
 * @param callback 回调函数，用于在验证完成后返回验证结果
 */
function validIdCard(rule: object, value: string, callback: (error?: Error) => void): void {
  if (
    !/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/.test(
      value
    )
  ) {
    callback(new Error("身份证号码格式不正确"));
  } else {
    callback();
  }
}

/**
 * 验证手机号码的合法性
 *
 * @param rule 验证规则对象，用于定义验证的规则和条件
 * @param value 待验证的手机号码字符串
 * @param callback 回调函数，用于在验证完成后返回验证结果
 */
function validPhone(rule: object, value: string, callback: (error?: Error) => void): void {
  if (!/^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(value)) {
    callback(new Error("手机号码格式不正确"));
  } else {
    callback();
  }
}
